<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>roundedcorners.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
  </script>

  <script src="static/js/doc.js">
  </script>

  <meta charset="utf8">
</head>

<body onload="prettyPrint()">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_ui_roundedcorners.js.html">roundedcorners.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line2"></a>// you may not use this file except in compliance with the License.
<a name="line3"></a>// You may obtain a copy of the License at
<a name="line4"></a>//
<a name="line5"></a>//     http://www.apache.org/licenses/LICENSE-2.0
<a name="line6"></a>//
<a name="line7"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line8"></a>// distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
<a name="line9"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line10"></a>// See the License for the specific language governing permissions and
<a name="line11"></a>// limitations under the License.
<a name="line12"></a>
<a name="line13"></a>// Copyright 2006 Google Inc. All Rights Reserved.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Definition of the RoundedCorners class. This depends on the
<a name="line17"></a> * GSE servlet: http://go/roundedcornerservlet.java
<a name="line18"></a> * The sevlet provides the images for that this class depends on for generating
<a name="line19"></a> * the rounded corners. See com.google.javascript.closure.RoundedCornerServlet
<a name="line20"></a> * for sample usage.
<a name="line21"></a> *
<a name="line22"></a> */
<a name="line23"></a>
<a name="line24"></a>goog.provide(&#39;goog.ui.RoundedCorners&#39;);
<a name="line25"></a>goog.provide(&#39;goog.ui.RoundedCorners.Corners&#39;);
<a name="line26"></a>
<a name="line27"></a>goog.require(&#39;goog.Uri&#39;);
<a name="line28"></a>goog.require(&#39;goog.color&#39;);
<a name="line29"></a>goog.require(&#39;goog.dom&#39;);
<a name="line30"></a>goog.require(&#39;goog.math.Size&#39;);
<a name="line31"></a>goog.require(&#39;goog.string&#39;);
<a name="line32"></a>goog.require(&#39;goog.style&#39;);
<a name="line33"></a>goog.require(&#39;goog.userAgent&#39;);
<a name="line34"></a>
<a name="line35"></a>/**
<a name="line36"></a> * Class for constructing the HTML for a rounded corner border based on the
<a name="line37"></a> * RoundedCornerServlet server class.
<a name="line38"></a> *
<a name="line39"></a> * @constructor
<a name="line40"></a> * @param {goog.Uri|string} servletUri The uri to the RoundedCornerServlet for
<a name="line41"></a> * fetching the rounded corner images.
<a name="line42"></a> */
<a name="line43"></a>goog.ui.RoundedCorners = function(servletUri) {
<a name="line44"></a>  this.servletUri_ = servletUri;
<a name="line45"></a>
<a name="line46"></a>  /**
<a name="line47"></a>   * Size of the border corners
<a name="line48"></a>   * @type {goog.math.Size}
<a name="line49"></a>   * @private
<a name="line50"></a>   */
<a name="line51"></a>  this.size_ = new goog.math.Size(8, 8);
<a name="line52"></a>
<a name="line53"></a>  /**
<a name="line54"></a>   * Which corners to show.
<a name="line55"></a>   * @type {number}
<a name="line56"></a>   * @private
<a name="line57"></a>   */
<a name="line58"></a>  this.cornersToShow_ = goog.ui.RoundedCorners.Corners.ALL;
<a name="line59"></a>};
<a name="line60"></a>
<a name="line61"></a>/**
<a name="line62"></a> * A convenience method to round the corners of a given element.
<a name="line63"></a> * To achieve the rounding, the rounded corners div replaces the element in its
<a name="line64"></a> * parent.  The element is added as the content of the rounded corners div.
<a name="line65"></a> *
<a name="line66"></a> * @param {Element} element The element to provide with rounded corners.
<a name="line67"></a> * @param {string} servletUri The uri to the RoundedCornerServlet for
<a name="line68"></a> * fetching the rounded corner images.
<a name="line69"></a> * @param {goog.math.Size} opt_borderThickness The rounded corners border
<a name="line70"></a> * see setBorderThickness().  If no value is supplied, (5, 5) will be used.
<a name="line71"></a> * @param {number} opt_corners The corners to round.  A bitwise integer.  If no
<a name="line72"></a> * corners are specified, goog.ui.RoundedCorners.Corners.ALL will be used.
<a name="line73"></a> */
<a name="line74"></a>goog.ui.RoundedCorners.roundElement = function(
<a name="line75"></a>    element, servletUri, opt_borderThickness, opt_corners) {
<a name="line76"></a>
<a name="line77"></a>  var roundedCorners = new goog.ui.RoundedCorners(servletUri);
<a name="line78"></a>
<a name="line79"></a>  roundedCorners.setColor(goog.style.getBackgroundColor(element));
<a name="line80"></a>
<a name="line81"></a>  // Look to the parent for a background color.
<a name="line82"></a>  var backgroundColor;
<a name="line83"></a>  var parent = /** @type {Element} */ (element.parentNode);
<a name="line84"></a>  backgroundColor = goog.style.getBackgroundColor(parent);
<a name="line85"></a>
<a name="line86"></a>  // Default to white if the color is invalid.
<a name="line87"></a>  /** @preserveTry */
<a name="line88"></a>  try {
<a name="line89"></a>    goog.color.parse(backgroundColor);
<a name="line90"></a>  } catch (ex) {
<a name="line91"></a>    backgroundColor = &#39;white&#39;;
<a name="line92"></a>  }
<a name="line93"></a>
<a name="line94"></a>  roundedCorners.setBackgroundColor(backgroundColor);
<a name="line95"></a>
<a name="line96"></a>  if (!goog.isDef(opt_corners)) {
<a name="line97"></a>    opt_corners = goog.ui.RoundedCorners.Corners.ALL;
<a name="line98"></a>  }
<a name="line99"></a>  roundedCorners.setCornersToShow(opt_corners);
<a name="line100"></a>
<a name="line101"></a>  if (!goog.isDef(opt_borderThickness)) {
<a name="line102"></a>    opt_borderThickness = new goog.math.Size(5, 5);
<a name="line103"></a>  }
<a name="line104"></a>  roundedCorners.setBorderThickness(opt_borderThickness);
<a name="line105"></a>
<a name="line106"></a>  var roundedContainer = goog.dom.htmlToDocumentFragment(
<a name="line107"></a>      roundedCorners.getBackgroundHtml());
<a name="line108"></a>
<a name="line109"></a>  parent.replaceChild(roundedContainer, element);
<a name="line110"></a>
<a name="line111"></a>  // Remove the content element, replace it with the element to round.
<a name="line112"></a>  goog.dom.removeNode(goog.dom.getLastElementChild(roundedContainer));
<a name="line113"></a>  goog.dom.appendChild(roundedContainer, element);
<a name="line114"></a>};
<a name="line115"></a>
<a name="line116"></a>/**
<a name="line117"></a> * Foreground color of the rounded corners
<a name="line118"></a> * @type {string}
<a name="line119"></a> * @private
<a name="line120"></a> */
<a name="line121"></a>goog.ui.RoundedCorners.prototype.color_ = &#39;#ff0000&#39;;
<a name="line122"></a>
<a name="line123"></a>/**
<a name="line124"></a> * Background color of the rounded corners
<a name="line125"></a> * @type {string}
<a name="line126"></a> * @private
<a name="line127"></a> */
<a name="line128"></a>goog.ui.RoundedCorners.prototype.bgColor_ = &#39;&#39;;
<a name="line129"></a>
<a name="line130"></a>/**
<a name="line131"></a> * Inner color of the rounded corners
<a name="line132"></a> * @type {string}
<a name="line133"></a> * @private
<a name="line134"></a> */
<a name="line135"></a>goog.ui.RoundedCorners.prototype.inColor_ = &#39;&#39;;
<a name="line136"></a>
<a name="line137"></a>/**
<a name="line138"></a> * HTML content that goes inside the template
<a name="line139"></a> * @type {string}
<a name="line140"></a> * @private
<a name="line141"></a> */
<a name="line142"></a>goog.ui.RoundedCorners.prototype.content_ = &#39;&#39;;
<a name="line143"></a>
<a name="line144"></a>/**
<a name="line145"></a> * Padding style for the internal content
<a name="line146"></a> * @type {string}
<a name="line147"></a> * @private
<a name="line148"></a> */
<a name="line149"></a>goog.ui.RoundedCorners.prototype.padding_ = &#39;&#39;;
<a name="line150"></a>
<a name="line151"></a>/**
<a name="line152"></a> * An explicit height for the HTML. If null, no height is specified
<a name="line153"></a> * @type {string?}
<a name="line154"></a> * @private
<a name="line155"></a> */
<a name="line156"></a>goog.ui.RoundedCorners.prototype.height_ = null;
<a name="line157"></a>
<a name="line158"></a>/**
<a name="line159"></a> * The format of the image. Either PNG or GIF
<a name="line160"></a> * @type {string}
<a name="line161"></a> * @private
<a name="line162"></a> */
<a name="line163"></a>goog.ui.RoundedCorners.prototype.imageFormat_ = &#39;png&#39;;
<a name="line164"></a>
<a name="line165"></a>/**
<a name="line166"></a> * The width of the border line. If 0, width == corner radius
<a name="line167"></a> * @type {number}
<a name="line168"></a> * @private
<a name="line169"></a> */
<a name="line170"></a>goog.ui.RoundedCorners.prototype.lineWidth_ = 0;
<a name="line171"></a>
<a name="line172"></a>/**
<a name="line173"></a> * Enum for specifying which corners to include.
<a name="line174"></a> * @enum {number}
<a name="line175"></a> */
<a name="line176"></a>goog.ui.RoundedCorners.Corners = {
<a name="line177"></a>  /**
<a name="line178"></a>   * Include just the top-left corner.
<a name="line179"></a>   */
<a name="line180"></a>  TOP_LEFT: 1,
<a name="line181"></a>
<a name="line182"></a>  /**
<a name="line183"></a>   * Include just the top-right corner.
<a name="line184"></a>   */
<a name="line185"></a>  TOP_RIGHT: 2,
<a name="line186"></a>
<a name="line187"></a>  /**
<a name="line188"></a>   * Include just the bottom-left corner.
<a name="line189"></a>   */
<a name="line190"></a>  BOTTOM_LEFT: 4,
<a name="line191"></a>
<a name="line192"></a>  /**
<a name="line193"></a>   * Include just the bottom-right corner.
<a name="line194"></a>   */
<a name="line195"></a>  BOTTOM_RIGHT: 8,
<a name="line196"></a>
<a name="line197"></a>  /**
<a name="line198"></a>   * Include just the left corners.
<a name="line199"></a>   */
<a name="line200"></a>  LEFT: 5, // TOP_LEFT | BOTTOM_LEFT
<a name="line201"></a>
<a name="line202"></a>  /**
<a name="line203"></a>   * Include just the right corners.
<a name="line204"></a>   */
<a name="line205"></a>  RIGHT: 10, // TOP_RIGHT | BOTTOM_RIGHT
<a name="line206"></a>
<a name="line207"></a>  /**
<a name="line208"></a>   * Include just the top corners.
<a name="line209"></a>   */
<a name="line210"></a>  TOP: 3, // TOP_LEFT | TOP_RIGHT
<a name="line211"></a>
<a name="line212"></a>  /**
<a name="line213"></a>   * Include just the bottom corners.
<a name="line214"></a>   */
<a name="line215"></a>  BOTTOM: 12, // BOTTOM_LEFT | BOTTOM_RIGHT
<a name="line216"></a>
<a name="line217"></a>  /**
<a name="line218"></a>   * Include all corners.
<a name="line219"></a>   */
<a name="line220"></a>  ALL: 15 // TOP |  BOTTOM
<a name="line221"></a>};
<a name="line222"></a>
<a name="line223"></a>/**
<a name="line224"></a> * Returns the foreground color
<a name="line225"></a> * @return {string} The color in hex format.
<a name="line226"></a> */
<a name="line227"></a>goog.ui.RoundedCorners.prototype.getColor = function() {
<a name="line228"></a>  return this.color_;
<a name="line229"></a>};
<a name="line230"></a>
<a name="line231"></a>
<a name="line232"></a>/**
<a name="line233"></a> * Sets the foreground color.
<a name="line234"></a> * @param {string} color The color in a format parsable by goog.color.parse().
<a name="line235"></a> */
<a name="line236"></a>goog.ui.RoundedCorners.prototype.setColor = function(color) {
<a name="line237"></a>  this.color_ = goog.color.parse(color).hex;
<a name="line238"></a>};
<a name="line239"></a>
<a name="line240"></a>
<a name="line241"></a>/**
<a name="line242"></a> * Returns the background color
<a name="line243"></a> * @return {string} The color in hex format or null for transparent.
<a name="line244"></a> */
<a name="line245"></a>goog.ui.RoundedCorners.prototype.getBackgroundColor = function() {
<a name="line246"></a>  return this.bgColor_;
<a name="line247"></a>};
<a name="line248"></a>
<a name="line249"></a>
<a name="line250"></a>/**
<a name="line251"></a> * Sets the background color.
<a name="line252"></a> * @param {string} bgColor The color in a format parsable by goog.color.parse()
<a name="line253"></a> * or empty string if transparent.
<a name="line254"></a> */
<a name="line255"></a>goog.ui.RoundedCorners.prototype.setBackgroundColor = function(bgColor) {
<a name="line256"></a>  if (goog.string.isEmpty(bgColor)) {
<a name="line257"></a>    this.bgColor_ = &#39;&#39;;
<a name="line258"></a>  } else {
<a name="line259"></a>    this.bgColor_ = goog.color.parse(bgColor).hex;
<a name="line260"></a>  }
<a name="line261"></a>};
<a name="line262"></a>
<a name="line263"></a>
<a name="line264"></a>/**
<a name="line265"></a> * Returns the inner color
<a name="line266"></a> * @return {string} The color in hex format or null for transparent.
<a name="line267"></a> */
<a name="line268"></a>goog.ui.RoundedCorners.prototype.getInnerColor = function() {
<a name="line269"></a>  return this.inColor_;
<a name="line270"></a>};
<a name="line271"></a>
<a name="line272"></a>
<a name="line273"></a>/**
<a name="line274"></a> * Sets the inner color.
<a name="line275"></a> * @param {string} inColor The color in a format parsable by goog.color.parse()
<a name="line276"></a> * or empty string if transparent.
<a name="line277"></a> */
<a name="line278"></a>goog.ui.RoundedCorners.prototype.setInnerColor = function(inColor) {
<a name="line279"></a>  if (goog.string.isEmpty(inColor)) {
<a name="line280"></a>    this.inColor_ = &#39;&#39;;
<a name="line281"></a>  } else {
<a name="line282"></a>    this.inColor_ = goog.color.parse(inColor).hex;
<a name="line283"></a>  }
<a name="line284"></a>};
<a name="line285"></a>
<a name="line286"></a>
<a name="line287"></a>/**
<a name="line288"></a> * Returns the border thickness. The height and width specifies the width and
<a name="line289"></a> * height of the corner images that form the arcs. The height dictates the
<a name="line290"></a> * thickness of the top and bottom borders and width dicates the thickness of
<a name="line291"></a> * the left and right borders.
<a name="line292"></a> *
<a name="line293"></a> * @return {goog.math.Size} The border size.
<a name="line294"></a> */
<a name="line295"></a>goog.ui.RoundedCorners.prototype.getBorderThickness = function() {
<a name="line296"></a>  return this.size_;
<a name="line297"></a>};
<a name="line298"></a>
<a name="line299"></a>
<a name="line300"></a>/**
<a name="line301"></a> * Sets the border thickness. The height and width specifies the width and
<a name="line302"></a> * height of the corner images that form the arcs. The height dictates the
<a name="line303"></a> * thickness of the top and bottom borders and width dicates the thickness of
<a name="line304"></a> * the left and right borders.
<a name="line305"></a> *
<a name="line306"></a> * @param {goog.math.Size} size The border size.
<a name="line307"></a> */
<a name="line308"></a>goog.ui.RoundedCorners.prototype.setBorderThickness = function(size) {
<a name="line309"></a>  this.size_ = size;
<a name="line310"></a>};
<a name="line311"></a>
<a name="line312"></a>
<a name="line313"></a>/**
<a name="line314"></a> * Returns the explicit height of the element creating the border or
<a name="line315"></a> * background.
<a name="line316"></a> * For the #getBorderHtml case, this usually isn&#39;t necessary to set as it will
<a name="line317"></a> * size to content. For the #getBackgroundHtml case, this may be necessary to
<a name="line318"></a> * set in certain cases in IE because of an off-by-1 bug in IE&#39;s bottom
<a name="line319"></a> * positioning code.
<a name="line320"></a> *
<a name="line321"></a> * @return {string?} The height as a style string (e.g. &#39;2px&#39; or &#39;3em&#39;).
<a name="line322"></a> */
<a name="line323"></a>goog.ui.RoundedCorners.prototype.getExplicitHeight = function() {
<a name="line324"></a>  return this.height_;
<a name="line325"></a>};
<a name="line326"></a>
<a name="line327"></a>
<a name="line328"></a>/**
<a name="line329"></a> * Sets the explicit height of the element creating the border or background.
<a name="line330"></a> * For the #getBorderHtml case, this usually isn&#39;t necessary to set as it will
<a name="line331"></a> * size to content. For the #getBackgroundHtml case, this may be necessary to
<a name="line332"></a> * set in certain cases in IE because of an off-by-1 bug in IE&#39;s bottom
<a name="line333"></a> * positioning code.
<a name="line334"></a> *
<a name="line335"></a> * @param {string} height The height as a style string (e.g. &#39;2px&#39; or &#39;3em&#39;).
<a name="line336"></a> */
<a name="line337"></a>goog.ui.RoundedCorners.prototype.setExplicitHeight = function(height) {
<a name="line338"></a>  this.height_ = height;
<a name="line339"></a>};
<a name="line340"></a>
<a name="line341"></a>
<a name="line342"></a>/**
<a name="line343"></a> * Returns the padding of the rounded corner border.
<a name="line344"></a> *
<a name="line345"></a> * @return {string} The padding as a style string (e.g. &#39;2px 4px&#39;).
<a name="line346"></a> *
<a name="line347"></a> */
<a name="line348"></a>goog.ui.RoundedCorners.prototype.getPadding = function() {
<a name="line349"></a>  return this.padding_;
<a name="line350"></a>};
<a name="line351"></a>
<a name="line352"></a>
<a name="line353"></a>/**
<a name="line354"></a> * Sets the padding of the rounded corner border.
<a name="line355"></a> *
<a name="line356"></a> * @param {string} padding The padding as a style string (e.g. &#39;2px 4px&#39;).
<a name="line357"></a> *
<a name="line358"></a> */
<a name="line359"></a>goog.ui.RoundedCorners.prototype.setPadding = function(padding) {
<a name="line360"></a>  this.padding_ = padding;
<a name="line361"></a>};
<a name="line362"></a>
<a name="line363"></a>
<a name="line364"></a>/**
<a name="line365"></a> * Returns the width of the border line. If 0, border is width/height
<a name="line366"></a> * of corners
<a name="line367"></a> *
<a name="line368"></a> * @return {number} The width.
<a name="line369"></a> *
<a name="line370"></a> */
<a name="line371"></a>goog.ui.RoundedCorners.prototype.getLineWidth = function() {
<a name="line372"></a>  return this.lineWidth_;
<a name="line373"></a>};
<a name="line374"></a>
<a name="line375"></a>
<a name="line376"></a>/**
<a name="line377"></a> * Sets the width of the border line. If 0, border is width/height
<a name="line378"></a> * of corners
<a name="line379"></a> *
<a name="line380"></a> * @param {number} lineWidth The width.
<a name="line381"></a> *
<a name="line382"></a> */
<a name="line383"></a>goog.ui.RoundedCorners.prototype.setLineWidth = function(lineWidth) {
<a name="line384"></a>  this.lineWidth_ = lineWidth;
<a name="line385"></a>};
<a name="line386"></a>
<a name="line387"></a>
<a name="line388"></a>/**
<a name="line389"></a> * Returns which corners to show
<a name="line390"></a> *
<a name="line391"></a> * @return {number} The corners to show.
<a name="line392"></a> *
<a name="line393"></a> */
<a name="line394"></a>goog.ui.RoundedCorners.prototype.getCornersToShow = function() {
<a name="line395"></a>  return this.cornersToShow_;
<a name="line396"></a>};
<a name="line397"></a>
<a name="line398"></a>
<a name="line399"></a>/**
<a name="line400"></a> * Sets which corners to show
<a name="line401"></a> *
<a name="line402"></a> * @param {number} cornersToShow The corners to show.
<a name="line403"></a> */
<a name="line404"></a>goog.ui.RoundedCorners.prototype.setCornersToShow = function(cornersToShow) {
<a name="line405"></a>  this.cornersToShow_ = cornersToShow;
<a name="line406"></a>};
<a name="line407"></a>
<a name="line408"></a>
<a name="line409"></a>/**
<a name="line410"></a> * Returns the image format. Currently, only png  and gif are supported.
<a name="line411"></a> *
<a name="line412"></a> * @return {string} The image format.
<a name="line413"></a> *
<a name="line414"></a> */
<a name="line415"></a>goog.ui.RoundedCorners.prototype.getImageFormat = function() {
<a name="line416"></a>  return this.imageFormat_;
<a name="line417"></a>};
<a name="line418"></a>
<a name="line419"></a>
<a name="line420"></a>/**
<a name="line421"></a> * Sets the image format. Currently, only png and gif are supported.
<a name="line422"></a> *
<a name="line423"></a> * @param {string} imageFormat The image format.
<a name="line424"></a> *
<a name="line425"></a> */
<a name="line426"></a>goog.ui.RoundedCorners.prototype.setImageFormat = function(imageFormat) {
<a name="line427"></a>  if (imageFormat != &#39;png&#39; &amp;&amp; imageFormat != &#39;gif&#39;) {
<a name="line428"></a>    throw Error(&#39;Image format must be \&#39;png\&#39; or \&#39;gif\&#39;&#39;);
<a name="line429"></a>  }
<a name="line430"></a>  this.imageFormat_ = imageFormat;
<a name="line431"></a>};
<a name="line432"></a>
<a name="line433"></a>
<a name="line434"></a>/**
<a name="line435"></a> * Returns the content of the borders
<a name="line436"></a> *
<a name="line437"></a> * @return {string} The content of the borders.
<a name="line438"></a> */
<a name="line439"></a>goog.ui.RoundedCorners.prototype.getContent = function() {
<a name="line440"></a>  return this.content_;
<a name="line441"></a>};
<a name="line442"></a>
<a name="line443"></a>
<a name="line444"></a>/**
<a name="line445"></a> * Sets the content of the borders
<a name="line446"></a> *
<a name="line447"></a> * @param {string} html The content of the borders.
<a name="line448"></a> */
<a name="line449"></a>goog.ui.RoundedCorners.prototype.setContent = function(html) {
<a name="line450"></a>  this.content_ = html;
<a name="line451"></a>};
<a name="line452"></a>
<a name="line453"></a>
<a name="line454"></a>/**
<a name="line455"></a> * Returns the HTML of a 9-cell table (when all corners are needed) that uses
<a name="line456"></a> * transparent images in the corners, a solid color on the sides, and the
<a name="line457"></a> * content in the middle cell.
<a name="line458"></a> *
<a name="line459"></a> * @return {string} The html of the table.
<a name="line460"></a> */
<a name="line461"></a>goog.ui.RoundedCorners.prototype.getBorderHtml = function() {
<a name="line462"></a>  // TODO: convert to client-side template mechanism when one exists
<a name="line463"></a>  // the html is built like a template so that this can later be
<a name="line464"></a>  // converted easily to a templating mechanism like JST.
<a name="line465"></a>  var sb = [];
<a name="line466"></a>  sb.push(&#39;&lt;table border=0 style=&quot;empty-cells:show;&#39; +
<a name="line467"></a>          &#39;border-collapse:{{%collapse}};&#39; +
<a name="line468"></a>          &#39;table-layout:fixed;width:100%;margin:0;padding:0;&#39; +
<a name="line469"></a>          &#39;height:{{%heightStyle}}&quot; cellspacing=0 cellpadding=0&gt;&#39;);
<a name="line470"></a>    if (this.cornersToShow_ &amp; goog.ui.RoundedCorners.Corners.TOP_LEFT ||
<a name="line471"></a>        this.cornersToShow_ &amp; goog.ui.RoundedCorners.Corners.BOTTOM_LEFT) {
<a name="line472"></a>      sb.push(&#39;&lt;col width=&quot;{{%w}}&quot;&gt;&#39;);
<a name="line473"></a>    }
<a name="line474"></a>    sb.push(&#39;&lt;col&gt;&#39;);
<a name="line475"></a>    if (this.cornersToShow_ &amp; goog.ui.RoundedCorners.Corners.TOP_RIGHT ||
<a name="line476"></a>        this.cornersToShow_ &amp; goog.ui.RoundedCorners.Corners.BOTTOM_LEFT) {
<a name="line477"></a>      sb.push(&#39;&lt;col width=&quot;{{%w}}&quot;&gt;&#39;);
<a name="line478"></a>    }
<a name="line479"></a>    if (this.cornersToShow_ &amp; goog.ui.RoundedCorners.Corners.TOP_LEFT ||
<a name="line480"></a>        this.cornersToShow_ &amp; goog.ui.RoundedCorners.Corners.TOP_RIGHT) {
<a name="line481"></a>      sb.push(&#39;&lt;tr&gt;&#39;);
<a name="line482"></a>        if (this.cornersToShow_ &amp; goog.ui.RoundedCorners.Corners.TOP_LEFT) {
<a name="line483"></a>          sb.push(&#39;&lt;td style=&quot;{{%tlStyle}}; width:{{%w}}px; height:{{%h}}px&quot;&gt;&#39; +
<a name="line484"></a>                  &#39;&lt;/td&gt;&#39;);
<a name="line485"></a>        }
<a name="line486"></a>        sb.push(&#39;&lt;td style=&quot;{{%tmColor}}&quot;&gt;&lt;/td&gt;&#39;);
<a name="line487"></a>        if (this.cornersToShow_ &amp; goog.ui.RoundedCorners.Corners.TOP_RIGHT) {
<a name="line488"></a>          sb.push(&#39;&lt;td style=&quot;{{%trStyle}}; width:{{%w}}px; height:{{%h}}px&quot;&gt;&#39; +
<a name="line489"></a>                  &#39;&lt;/td&gt;&#39;);
<a name="line490"></a>        }
<a name="line491"></a>      sb.push(&#39;&lt;/tr&gt;&#39;);
<a name="line492"></a>    }
<a name="line493"></a>    sb.push(&#39;&lt;tr&gt;&#39;);
<a name="line494"></a>      if (this.cornersToShow_ &amp; goog.ui.RoundedCorners.Corners.TOP_LEFT ||
<a name="line495"></a>          this.cornersToShow_ &amp; goog.ui.RoundedCorners.Corners.BOTTOM_LEFT) {
<a name="line496"></a>        sb.push(&#39;&lt;td style=&quot;{{%mlStyle}};{{%mlColor}};width:{{%w}}px;&quot;&gt;&lt;/td&gt;&#39;);
<a name="line497"></a>      }
<a name="line498"></a>      sb.push(&#39;&lt;td style=&quot;padding: {{%p}}&quot;&gt;{{%content}}&lt;/td&gt;&#39;);
<a name="line499"></a>      if (this.cornersToShow_ &amp; goog.ui.RoundedCorners.Corners.TOP_RIGHT ||
<a name="line500"></a>          this.cornersToShow_ &amp; goog.ui.RoundedCorners.Corners.BOTTOM_RIGHT) {
<a name="line501"></a>        sb.push(&#39;&lt;td style=&quot;{{%mrStyle}}; {{%mrColor}};width:{{%w}}px;&quot;&gt;&lt;/td&gt;&#39;);
<a name="line502"></a>      }
<a name="line503"></a>    sb.push(&#39;&lt;/tr&gt;&#39;);
<a name="line504"></a>    if (this.cornersToShow_ &amp; goog.ui.RoundedCorners.Corners.BOTTOM_LEFT ||
<a name="line505"></a>        this.cornersToShow_ &amp; goog.ui.RoundedCorners.Corners.BOTTOM_RIGHT) {
<a name="line506"></a>      sb.push(&#39;&lt;tr&gt;&#39;);
<a name="line507"></a>        if (this.cornersToShow_ &amp; goog.ui.RoundedCorners.Corners.BOTTOM_LEFT) {
<a name="line508"></a>          sb.push(&#39;&lt;td style=&quot;{{%blStyle}} width:{{%w}}px; height:{{%h}}px;&quot;&gt;&#39; +
<a name="line509"></a>                  &#39;&lt;/td&gt;&#39;);
<a name="line510"></a>        }
<a name="line511"></a>        sb.push(&#39;&lt;td style=&quot;{{%bmColor}}&quot;&gt;&lt;/td&gt;&#39;);
<a name="line512"></a>        if (this.cornersToShow_ &amp; goog.ui.RoundedCorners.Corners.BOTTOM_RIGHT) {
<a name="line513"></a>          sb.push(&#39;&lt;td style=&quot;{{%brStyle}};width:{{%w}}px; height:{{%h}}px&quot;&gt;&#39; +
<a name="line514"></a>                  &#39;&lt;/td&gt;&#39;);
<a name="line515"></a>        }
<a name="line516"></a>      sb.push(&#39;&lt;/tr&gt;&#39;);
<a name="line517"></a>    }
<a name="line518"></a>  sb.push(&#39;&lt;/table&gt;&#39;);
<a name="line519"></a>
<a name="line520"></a>  return this.performTemplateSubstitutions_(sb.join(&#39;&#39;));
<a name="line521"></a>};
<a name="line522"></a>
<a name="line523"></a>
<a name="line524"></a>/**
<a name="line525"></a> * Returns the HTML for a relatively positioned DIV that includes four
<a name="line526"></a> * absolutely positioned DIVs for the corner images and a DIV for the content.
<a name="line527"></a> *
<a name="line528"></a> * @return {string} The html of the table.
<a name="line529"></a> */
<a name="line530"></a>goog.ui.RoundedCorners.prototype.getBackgroundHtml = function() {
<a name="line531"></a>  // TODO: convert to client-side template mechanism when one exists
<a name="line532"></a>  // the html is built like a template so that this can later be converted
<a name="line533"></a>  // easily to a templating mechanism like JST.
<a name="line534"></a>  var sb = [];
<a name="line535"></a>  sb.push(&#39;&lt;div style=&quot;position:relative;padding:{{%p}};&#39; +
<a name="line536"></a>          &#39;background-color:{{%color}};height:{{%heightStyle}}&quot;&gt;&#39;);
<a name="line537"></a>    if (this.cornersToShow_ &amp; goog.ui.RoundedCorners.Corners.TOP_LEFT) {
<a name="line538"></a>      sb.push(&#39;&lt;div style=&quot;{{%tlStyle}};width:{{%w}}px; height:{{%h}}px;&#39; +
<a name="line539"></a>              &#39;position:absolute;top:0;left:0;font-size:0&quot;&gt;&lt;/div&gt;&#39;);
<a name="line540"></a>    }
<a name="line541"></a>    if (this.cornersToShow_ &amp; goog.ui.RoundedCorners.Corners.BOTTOM_LEFT) {
<a name="line542"></a>      sb.push(&#39;&lt;div style=&quot;{{%blStyle}};width:{{%w}}px; height:{{%h}}px;&#39; +
<a name="line543"></a>              &#39;position:absolute;bottom:0px;left:0;font-size:0&quot;&gt;&lt;/div&gt;&#39;);
<a name="line544"></a>    }
<a name="line545"></a>    if (this.cornersToShow_ &amp; goog.ui.RoundedCorners.Corners.BOTTOM_RIGHT) {
<a name="line546"></a>      sb.push(&#39;&lt;div style=&quot;{{%brStyle}};width:{{%w}}px; height:{{%h}}px;&#39; +
<a name="line547"></a>              &#39;position:absolute;bottom:0px;right:0;font-size:0&quot;&gt;&lt;/div&gt;&#39;);
<a name="line548"></a>    }
<a name="line549"></a>    if (this.cornersToShow_ &amp; goog.ui.RoundedCorners.Corners.TOP_RIGHT) {
<a name="line550"></a>      sb.push(&#39;&lt;div style=&quot;{{%trStyle}};width:{{%w}}px; height:{{%h}}px;&#39; +
<a name="line551"></a>              &#39;position:absolute;top:0;right:0;font-size:0&quot;&gt;&lt;/div&gt;&#39;);
<a name="line552"></a>    }
<a name="line553"></a>    sb.push(&#39;&lt;div&gt;{{%content}}&lt;/div&gt;&#39;);
<a name="line554"></a>  sb.push(&#39;&lt;/div&gt;&#39;);
<a name="line555"></a>
<a name="line556"></a>  return this.performTemplateSubstitutions_(sb.join(&#39;&#39;));
<a name="line557"></a>};
<a name="line558"></a>
<a name="line559"></a>
<a name="line560"></a>/**
<a name="line561"></a> * Performs the substitutions in the templates to values determined at runtime.
<a name="line562"></a> * @param {string} htmlTemplate The template to use.
<a name="line563"></a> * @return {string} The template with the substitutions.
<a name="line564"></a> * @private
<a name="line565"></a> */
<a name="line566"></a>goog.ui.RoundedCorners.prototype.performTemplateSubstitutions_ =
<a name="line567"></a>    function(htmlTemplate) {
<a name="line568"></a>  var html = htmlTemplate;
<a name="line569"></a>  var ctx = this.getCtx_();
<a name="line570"></a>  for (var key in ctx) {
<a name="line571"></a>    var regex = new RegExp(&#39;{{%&#39; + key + &#39;}}&#39;, &#39;g&#39;);
<a name="line572"></a>    html = html.replace(regex, ctx[key]);
<a name="line573"></a>  }
<a name="line574"></a>  return html;
<a name="line575"></a>};
<a name="line576"></a>
<a name="line577"></a>
<a name="line578"></a>/**
<a name="line579"></a> * Returns the context object used by the template mechanism
<a name="line580"></a> * @return {Object} The context object.
<a name="line581"></a> * @private
<a name="line582"></a> */
<a name="line583"></a>goog.ui.RoundedCorners.prototype.getCtx_ = function() {
<a name="line584"></a>  var colorHex = this.color_.substring(1);
<a name="line585"></a>  var ctx = {};
<a name="line586"></a>  ctx[&#39;tlStyle&#39;] = this.getCornerStyle_(&#39;tl&#39;);
<a name="line587"></a>  ctx[&#39;trStyle&#39;] = this.getCornerStyle_(&#39;tr&#39;);
<a name="line588"></a>  ctx[&#39;mlStyle&#39;] = &#39;&#39;;
<a name="line589"></a>  ctx[&#39;mrStyle&#39;] = &#39;&#39;;
<a name="line590"></a>  ctx[&#39;blStyle&#39;] = this.getCornerStyle_(&#39;bl&#39;);
<a name="line591"></a>  ctx[&#39;brStyle&#39;] = this.getCornerStyle_(&#39;br&#39;);
<a name="line592"></a>  if (this.cornersToShow_ == goog.ui.RoundedCorners.Corners.RIGHT) {
<a name="line593"></a>    ctx[&#39;tlStyle&#39;] = ctx[&#39;mlStyle&#39;] = ctx[&#39;blStyle&#39;] = &#39;display:none&#39;;
<a name="line594"></a>  } else if (this.cornersToShow_ == goog.ui.RoundedCorners.Corners.LEFT) {
<a name="line595"></a>    ctx[&#39;trStyle&#39;] = ctx[&#39;mrStyle&#39;] = ctx[&#39;brStyle&#39;] = &#39;display:none&#39;;
<a name="line596"></a>  }
<a name="line597"></a>
<a name="line598"></a>  if (this.height_ != null) {
<a name="line599"></a>    ctx[&#39;heightStyle&#39;] = this.height_;
<a name="line600"></a>  } else {
<a name="line601"></a>    ctx[&#39;heightStyle&#39;] = goog.userAgent.IE &amp;&amp; goog.userAgent.VERSION &lt; 7 ?
<a name="line602"></a>                            &#39;0px;&#39; : &#39;auto;&#39;;
<a name="line603"></a>  }
<a name="line604"></a>
<a name="line605"></a>  ctx[&#39;color&#39;] = this.color_;
<a name="line606"></a>  ctx[&#39;mlColor&#39;] = this.colorStyleFor_(&#39;left&#39;);
<a name="line607"></a>  ctx[&#39;mrColor&#39;] = this.colorStyleFor_(&#39;right&#39;);
<a name="line608"></a>  ctx[&#39;tmColor&#39;] = this.colorStyleFor_(&#39;top&#39;);
<a name="line609"></a>  ctx[&#39;bmColor&#39;] = this.colorStyleFor_(&#39;bottom&#39;);
<a name="line610"></a>  ctx[&#39;collapse&#39;] = this.lineWidth_ ? (goog.userAgent.IE ? &#39;collapse&#39; : &#39;&#39;) :
<a name="line611"></a>      &#39;collapse&#39;;
<a name="line612"></a>  ctx[&#39;w&#39;] = this.size_.width;
<a name="line613"></a>  ctx[&#39;h&#39;] = this.size_.height;
<a name="line614"></a>  ctx[&#39;p&#39;] = this.padding_;
<a name="line615"></a>  ctx[&#39;content&#39;] = this.content_;
<a name="line616"></a>  return ctx;
<a name="line617"></a>};
<a name="line618"></a>
<a name="line619"></a>
<a name="line620"></a>/**
<a name="line621"></a> * Get the CSS style for a given side with the current diplay parameters.
<a name="line622"></a> * Will return either a background or border color
<a name="line623"></a> * @param {string} side The side: left|top|right|bottom.
<a name="line624"></a> * @return {string} The style.
<a name="line625"></a> * @private
<a name="line626"></a> */
<a name="line627"></a>goog.ui.RoundedCorners.prototype.colorStyleFor_ = function(side) {
<a name="line628"></a>  return this.lineWidth_ ? &#39;border-&#39; + side + &#39;: &#39; +
<a name="line629"></a>      this.lineWidth_ + &#39;px solid &#39; + this.color_ :
<a name="line630"></a>      &#39;background-color:&#39; + this.color_;
<a name="line631"></a>};
<a name="line632"></a>
<a name="line633"></a>/**
<a name="line634"></a> * Returns the background image style string that uses AlphaImageLoader for IE6
<a name="line635"></a> * and background-images for other browsers
<a name="line636"></a> * @param {string} corner The corner of the image.
<a name="line637"></a> * @return {string} The style string.
<a name="line638"></a> * @private
<a name="line639"></a> */
<a name="line640"></a>goog.ui.RoundedCorners.prototype.getCornerStyle_ = function(corner) {
<a name="line641"></a>  var uri = this.createUri_(corner);
<a name="line642"></a>  if ((goog.string.isEmpty(this.color_) ||
<a name="line643"></a>       goog.string.isEmpty(this.bgColor_) ||
<a name="line644"></a>       goog.string.isEmpty(this.inColor_)) &amp;&amp; goog.userAgent.IE &amp;&amp;
<a name="line645"></a>       goog.userAgent.VERSION &gt; 5.5 &amp;&amp; goog.userAgent.VERSION &lt; 7) {
<a name="line646"></a>    // if need transparency, must do this in &lt; IE7
<a name="line647"></a>    return &#39;filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\&#39;&#39; +
<a name="line648"></a>           uri + &#39;\&#39;, sizingMethod=\&#39;crop\&#39;)&#39;;
<a name="line649"></a>  } else {
<a name="line650"></a>    return &#39;background: url(&#39; + uri + &#39;) no-repeat top left;&#39;;
<a name="line651"></a>  }
<a name="line652"></a>};
<a name="line653"></a>
<a name="line654"></a>
<a name="line655"></a>/**
<a name="line656"></a> * Returns the image Uri for a specific corner image.
<a name="line657"></a> * @param {string} corner The corner of the image.
<a name="line658"></a> * @return {goog.Uri} The uri.
<a name="line659"></a> * @private
<a name="line660"></a> */
<a name="line661"></a>goog.ui.RoundedCorners.prototype.createUri_ = function(corner) {
<a name="line662"></a>  // e.g. rc?a=tl&amp;c=#aaa&amp;w=8&amp;h=8
<a name="line663"></a>  var uri = new goog.Uri(this.servletUri_);
<a name="line664"></a>  uri.setParameterValue(&#39;a&#39;, corner);
<a name="line665"></a>  uri.setParameterValue(&#39;c&#39;, this.removeHash_(this.color_));
<a name="line666"></a>  uri.setParameterValue(&#39;bc&#39;, this.removeHash_(this.bgColor_));
<a name="line667"></a>  uri.setParameterValue(&#39;ic&#39;, this.removeHash_(this.inColor_));
<a name="line668"></a>  uri.setParameterValue(&#39;w&#39;, String(this.size_.width));
<a name="line669"></a>  uri.setParameterValue(&#39;h&#39;, String(this.size_.height));
<a name="line670"></a>  uri.setParameterValue(&#39;lw&#39;, String(this.lineWidth_));
<a name="line671"></a>  uri.setParameterValue(&#39;m&#39;, this.imageFormat_);
<a name="line672"></a>  return uri;
<a name="line673"></a>};
<a name="line674"></a>
<a name="line675"></a>
<a name="line676"></a>/**
<a name="line677"></a> * Helper function to remove hash from the color string
<a name="line678"></a> * @param {string} s The string to remove the has from.
<a name="line679"></a> * @return {string} The color name without the hash.
<a name="line680"></a> * @private
<a name="line681"></a> */
<a name="line682"></a>goog.ui.RoundedCorners.prototype.removeHash_ = function(s) {
<a name="line683"></a>  if (goog.string.startsWith(s, &#39;#&#39;)) {
<a name="line684"></a>    return s.substring(1);
<a name="line685"></a>  }
<a name="line686"></a>  return s;
<a name="line687"></a>};
</pre>


</body>
</html>
